package com.hundsun.fcp;

import android.app.Application;
import android.content.Context;

import com.hundsun.fcp.webplugin.WebPluginConfig;
import com.hundsun.fcp.webplugin.util.FileUtil;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.umeng.update.UmengUpdateAgent;

public class FcpApplication extends Application {

	private static FcpApplication instance;
	
	@Override
	public void onCreate() {
		super.onCreate();
		instance = this ;
		WebPluginConfig.init(this) ;
		initImageLoader(this) ;
		UmengUpdateAgent.setUpdateOnlyWifi(false); //在任意网络环境下都进行更新自动提醒  
	}

	public static FcpApplication getInstance() {
		return instance;
	}
	
	public static void initImageLoader(Context context) { 
		if (ImageLoader.getInstance().isInited()) {
			return;
		}
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				context)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.memoryCache(new WeakMemoryCache())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.diskCache(
						new UnlimitedDiscCache(WebPluginConfig.getImgDir(), null,
								new FileNameGenerator() {
									@Override
									public String generate(String s) {
										return FileUtil.getNameFromPath(s);
									}
								}))
				.writeDebugLogs() // Remove
				.build();
		ImageLoader.getInstance().init(config);
	}
}
